﻿using LightCAD.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Joins;
using System.Text;
using System.Threading.Tasks;

namespace QdArch.Shapes
{
    /// <summary>
    /// 双跑楼梯
    /// </summary>
    public class DogleggedStair : IShape2dProvider
    {
        public ComponentShape2d[] GetShapes(string category)
        {
            string subCategory = StairCategory.DogleggedStair.ToString();
            var list = new List<ComponentShape2d>
            {
                CreateShape(subCategory,"DogleggedStair", nameof(GetShape_双跑楼梯), GetShape_双跑楼梯, ""),
            };
            return list.ToArray();
        }

        public bool IsSupportCategory(string category)
        {
            return (category == ArchCategory.Stair.ToString());
        }
        private List<ICurve2d> GetShape_双跑楼梯(LcParameterSet pset) 
        {
            var sc = new Shape2dCreator();
            var stepwidth = pset.GetValue<double>("StepWidth");
            var stepheight = pset.GetValue<double>("StepHeight");
            var stepnum = pset.GetValue<int>("StepNum"); 
            var ladderwidth = pset.GetValue<double>("LadderWidth");
            var platwidth = pset.GetValue<double>("PlatWidth");
            var platlen = pset.GetValue<double>("PlatLen");
            for (int i = 0; i < stepnum; i++)
            {
                sc.DrawRect(new Vector2d(0, i*stepwidth), new Vector2d(ladderwidth, (i+1)* stepwidth));
                sc.DrawRect(new Vector2d(platlen - ladderwidth, (stepnum-i-1) * stepwidth), new Vector2d(platlen, (stepnum-i) * stepwidth)) ;
            }
            sc.DrawRect(new Vector2d(0, stepnum*stepwidth), new Vector2d(platlen, stepnum * stepwidth + platwidth));
            return sc.Curves;
        }
        public ComponentShape2d CreateShape(string subCategory, string name, string funcName, Func<LcParameterSet, List<ICurve2d>> func, string description)
        {
            var displayName = funcName.Substring(funcName.IndexOf("_") + 1);
            return new ComponentShape2d
            {
                Category = ArchCategory.Stair.ToString(),
                SubCategory = subCategory,
                Name = name,
                DisplayName = displayName,
                Description = description,
                Generate = func
            };
        }
    }
}
